package com.xiaolei.library.Widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

/**
 * 高度自适应的网格布局
 */
public class NoScrollGridView extends GridView
{
    public NoScrollGridView(Context context)
    {
        this(context, null);
    }

    public NoScrollGridView(Context context, AttributeSet attrs)
    {
        this(context, attrs, 0);
    }

    public NoScrollGridView(Context context, AttributeSet attrs, int defStyleAttr)
    {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
        int heightSpec;
        if (getLayoutParams().height == LayoutParams.WRAP_CONTENT)
        {
            // a special meaning, hence we can't use them to describe height.
            heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        } else
        {
            // Any other height should be respected as is.
            heightSpec = heightMeasureSpec;
        }
        super.onMeasure(widthMeasureSpec, heightSpec);
    }
}
